//
//  KABExhibitionTCell.m
//  kabu
//
//  Created by XiangDongMBP on 2017/2/10.
//  Copyright © 2017年 East. All rights reserved.
//

#import "KABExhibitionTCell.h"
#import "KABModel.h"
#import <YYWebImage.h>
#import "UIColor+XDHex.h"
#import "GlobalHeader.h"
#import "NSString+XDNSDate.h"
#import "NSDate+XDTimerFormatter.h"

@implementation KABExhibitionTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.buyBtn.layer.masksToBounds = YES;
    self.buyBtn.layer.cornerRadius = CGRectGetHeight(self.buyBtn.bounds) / 2.0;
    [self.buyBtn addTarget:self action:@selector(buyBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(posterImgViewTapped:)];
    [self.posterImgView addGestureRecognizer:tapGesture];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)posterImgViewTapped:(UIGestureRecognizer *)gesture {
    if ([self.delegate respondsToSelector:@selector(kABExhibitionTCell:imgViewTapped:)]) {
        [self.delegate kABExhibitionTCell:self imgViewTapped:(UIImageView *)gesture.view];
    }
}

- (void)buyBtnTapped:(UIButton *)btn {
    if ([self.delegate respondsToSelector:@selector(kABExhibitionTCell:buyBtnTapped:)]) {
        [self.delegate kABExhibitionTCell:self buyBtnTapped:btn];
    }
}

- (void)configViewWithExhListItem:(KABExhListItem *)item {
    [self.posterImgView yy_setImageWithURL:[NSURL URLWithString:item.cover_image_url] placeholder:[KABDefaultVarModel sharedInstance].rectDefaultImg];
    self.posterImgView.userInteractionEnabled = NO;
    
    self.titleLabel.text = item.name;
    NSString *startTime = [[item.start_time xd_yyyyMMddHHmmssStrToDate] xd_yyyyMMdd];
    NSString *endTime = [[item.end_time xd_yyyyMMddHHmmssStrToDate] xd_MMdd];
    self.timeLabel.text = [NSString stringWithFormat:@"%@-%@\n%@ %@ %@ %@", startTime, endTime, item.province, item.city, item.district, item.address];
    
    if (item.is_buyable) {
        [self.buyBtn setImage:[UIImage imageNamed:@"exhibition_ticket"] forState:UIControlStateNormal];
        [self.buyBtn setTitle:@"  立即购票" forState:UIControlStateNormal];
        self.buyBtn.selected = NO;
        self.buyBtn.backgroundColor = [UIColor xd_colorWithHex:KABGlobalColorTabBarItemColor];
    } else {
        [self.buyBtn setImage:[UIImage imageNamed:@"exhibition_praise"] forState:UIControlStateNormal];
        [self.buyBtn setImage:[UIImage imageNamed:@"cosplay_praise_base_sel"] forState:UIControlStateSelected];
        [self.buyBtn setTitle:@"  关注展会" forState:UIControlStateNormal];
        [self.buyBtn setTitle:@"  已关注" forState:UIControlStateSelected];
        self.buyBtn.selected = item.is_collected;
        self.buyBtn.backgroundColor = [UIColor xd_colorWithHex:KABGlobalColorRedBtnBorderColor];
    }
    self.buyBtn.hidden = NO;
    self.buyBtn.userInteractionEnabled = NO;
    
    self.priceLabel.hidden = YES;
    self.cntLabel.hidden = YES;
}

@end

@implementation KABExhibitionTCell (ExhibitionDetail)
- (void)configViewWithExhDetail:(KABExhListItem *)item {
    [self.posterImgView yy_setImageWithURL:[NSURL URLWithString:item.cover_image_url] placeholder:[KABDefaultVarModel sharedInstance].rectDefaultImg];
    self.posterImgView.userInteractionEnabled = YES;
    
    self.titleLabel.text = item.name;
    NSString *startTime = [[item.start_time xd_yyyyMMddHHmmssStrToDate] xd_yyyyMMdd];
    NSString *endTime = [[item.end_time xd_yyyyMMddHHmmssStrToDate] xd_MMdd];
    self.timeLabel.text = [NSString stringWithFormat:@"%@-%@\n%@ %@ %@ %@", startTime, endTime, item.province, item.city, item.district, item.address];
    
    self.buyBtn.hidden = YES;
    
    self.priceLabel.hidden = NO;
    self.priceLabel.text = [NSString stringWithFormat:@"￥%.2f", item.selOriginalPrice / 100.0];
    
    self.cntLabel.hidden = YES;
}

@end


@implementation KABExhibitionTCell (ExhSureOrder)
- (void)configViewWithExhSureOrder:(KABExhListItem *)item {
    [self.posterImgView yy_setImageWithURL:[NSURL URLWithString:item.cover_image_url] placeholder:[KABDefaultVarModel sharedInstance].rectDefaultImg];
    
    self.titleLabel.text = item.name;
    NSString *startTime = [[item.start_time xd_yyyyMMddHHmmssStrToDate] xd_yyyyMMddHHmm];
    self.timeLabel.text = [NSString stringWithFormat:@"%@\n%@", item.selTicketType, startTime];
    
    self.buyBtn.hidden = YES;
    self.priceLabel.hidden = NO;
    self.priceLabel.text = [NSString stringWithFormat:@"￥%.2f", item.selOriginalPrice / 100.0];
    self.cntLabel.hidden = NO;
    self.cntLabel.text = [NSString stringWithFormat:@"X%zd", item.number];
}
@end

